<?php
$GLOBALS = array(
    'objetID' => 1
);
/**
 * ERROR CODE 0200-0299
 *
 * */
class MENU_product {
	private $error;
	private $db;
	
	public function __construct() {
		// $check = $GLOBALS['check'];
		// $check->dontCheck('demo',array(1));
		$this->error = $GLOBALS['error'];
		$this->db = new DB();
		
	}
	public function getProductInfo($productID) {
		global $GLOBALS;
		if( empty($productID) ){
			$this->error->setError(0200,"empty product ID");
			return false;
		}
		$sql = "SELECT * FROM product WHERE id = ".$productID." AND object_id = ". $GLOBALS['objetID'];
		$dbResult = $this->db->query($sql);
		if($dbResult === false ) {
			return false;
		}
		return $dbResult;
	}
	public function createNewProduct($sortID) {
		if( empty($sortID) ) {
			$this->error->setError(0201,"empty sort ID");
			return false;
		}
		$sql = "INSERT INTO product (object_id, sort_id, price, name_am,description_am,name_ru,description_ru,name_en,description_en) VALUES (".$GLOBALS['objetID'].", ".$sortID.", '0','Նոր ուտեստ', 'Նկարագրություն','Новый  продукт','описание','New product','Description')";
		$dbResult = $this->db->query($sql);
		if($dbResult === false ) {
			return false;
		}
		$id = $this->db->lastInsertID();
		return $id;
	}
	public function updateProductInfo($assocArray) {
		Global $GLOBALS;
		$productID = $assocArray['id'];
		if( empty($productID) ){
			$this->error->setError(0202,"empty product ID");
			return false;
		}
		$sql = "UPDATE product SET name_am = '".$assocArray['name_am']."',name_ru = '".$assocArray['name_ru']."',name_en = '".$assocArray['name_en']."',description_am = '".$assocArray['description_am']."',description_ru = '".$assocArray['description_ru']."',description_en = '".$assocArray['description_en']."',price = ".$assocArray['price'].", status = ".$assocArray['status']." WHERE object_id = ".$GLOBALS['objetID']." AND id = ".$productID;
		$dbResult = $this->db->query($sql);
		if($dbResult === false ) {
			return false;
		}
		return $dbResult;
	}
	
}















?>